<?php


function thumb($filename){
	        $f=explode('/',$filename);
	        $files=end($f);

	        $name='thumb_'.$files;
            array_pop($f);
	        $f[]=$name;
	        $newsname=implode('/',$f);
         //    print_r($f);
	        // die;

			$old=getimagesize($filename);
			$new_width=$old[0]/2;
			$new_height=$old[1]/2;

			print_r($old);
			switch ($old[2]) {
				case '1':
					$old_img=imagecreatefromgif($filename);
					break;
				case '2':
					$old_img=imagecreatefromjpeg($filename);
					break;
				case '3':
					$old_img=imagecreatefrompng($filename);
					break;
				default:
					break;
			}


			$new_img=imagecreatetruecolor($new_width,$new_height);
			imagecopyresized($new_img,$old_img,0,0,0,0,$new_width,$new_height,$old[0],$old[1]);
			ob_clean();

			switch ($old[2]) {
				case '1':
					imagegif($new_img,$newsname);
					break;
				case '2':
					imagejpeg($new_img,$newsname);
					break;
				case '3':
					imagepng($new_img,$newsname);
					break;
				default:
					break;
			}

			return $newsname;

			imagedestroy($new_img);
}